home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Atari Compendium
/
The Atari Compendium (Toad Computers) (1994).iso
/
files
/
umich
/
telecomm
/
uemlsrc.arc
/
word.c
< prev
next >
Wrap
C/C++ Source or Header
|
1987-08-24
|
18KB
|
589 lines
/*
* The routines in this file
* implement commands that work word at
* a time. There are all sorts of word mode
* commands. If I do any sentence and/or paragraph
* mode commands, they are likely to be put in
* this file. Added R.D.R Feb. 1986.
*/
#include <stdio.h>
#include <ctype.h>
#include "ed.h"
/* Word wrap or fill wrap depending on f flag value.
* Back-over whatever precedes the point on the current line and
* stop on the first word-break or the beginning of the line.
* If we reach the beginning of the line, jump back to the end of the
* word and start a new line. Otherwise, break the line at the
* word-break, eat it, and jump back to the end of the word.
* Returns TRUE on success, FALSE on errors.
*/
wrapword(f, n)
register int f, n;
{
int oldp;
oldp = curwp->w_dotp;
if (! backwword(NULL, 1)) /* punctuation marks */
return(FALSE);
if (oldp != curwp->w_dotp && curwp->w_doto)
{
if (! backdel(NULL, 1))
return(FALSE);
if (! newline(TRUE, 1))
return(FALSE);
}
if(f)
return(forwwword(NULL, 1));
return(forwwword(NULL, 1) && forwchar(NULL, 1) && backdel(NULL, 1));
}
/* FILLPAR Meta command Fill paragraph to specified fill column and indent
* column. Bound to M-Q.
*/
fillpar(f, n)
register int f, n;
{
register int s;
register short omo;
register LINE *omp;
if (n > 1)
setfillcol(f, n);
if(fillcol == 0)
{
mlwrite("Fill column not set");
(*term.t_beep)();
return(FALSE);
}
omp = curwp->w_markp;
omo = curwp->w_marko;
curwp->w_markp = curwp->w_dotp;
curwp->w_marko = curwp->w_doto;
gotbop(FALSE, 1);
forwchar(FALSE, 1);
while((n = ltrw(FALSE, 1)) != EOF && n != NULL)
forwline(NULL, 1);
gotbop(FALSE, 1);
forwchar(FALSE, 1);
while (TRUE)
{
if (llength(curwp->w_dotp) == NULL)
break;
if (curwp->w_dotp == curbp->b_linep)
break;
if (getccol(FALSE) > fillcol)
{
if (wrapword(TRUE, NULL) == FALSE)
break;
continue;
}
if (curwp->w_doto == llength(curwp->w_dotp)
&& getccol(FALSE) <= fillcol)
{
if (forwchar(FALSE, 1) == FALSE)
break;
if (curwp->w_dotp == curbp->b_linep)
break; /* @ EOB */
if (llength(curwp->w_dotp) == NULL)
break; /* @ EOP */
if (backchar(FALSE, 1) == FALSE)
break;
if (clowsp(FALSE, NULL) == FALSE)
break;
continue;
}
if (forwchar(FALSE, 1) == FALSE)
break;
}
curwp->w_dotp = curwp->w_markp;
curwp->w_doto = curwp->w_marko;
curwp->w_markp = omp;
curwp->w_marko = omo;
curwp->w_flag |= WFHARD;
curgoal = getccol(FALSE);
return(TRUE);
}
/*
* PRIVATE VERSION OF INWORD() FOR WRAPWORD(), FORWWORD(), AND BACKWWORD()
* Return FALSE if the character at dot
* is a space character or above 0x7e.
* Otherwise return TRUE. Any printing
* character below <DEL> that is not
* a space character may appear inside a
* word to be wrapped. Using a special version
* of inword() allows us to keep the usual meaning
* of word for regular movement.
*/
static
inwword()
{
register int c;
if (curwp->w_doto == llength(curwp->w_dotp))
return (FALSE);
c = lgetc(curwp->w_dotp, curwp->w_doto);
if (isspace(c) || c> '~')
return (FALSE);
return (TRUE);
}
/*
* PRIVATE VERSION OF BACKWORD() FOR WRAPWORD() AND FORWWWORD()
* Move the cursor backward by
* "n" words. All of the details of motion
* are performed by the "backchar" and "forwchar"
* routines. Error if you try to move beyond
* the buffers.
*/
static
backwword(f, n)
register int f, n;
{
if (backchar(FALSE, 1) == FALSE)
return (FALSE);
while (inwword() == FALSE)
{
if (backchar(FALSE, 1) == FALSE)
return (FALSE);
}
while (inwword() != FALSE)
{
if (backchar(FALSE, 1) == FALSE)
return (FALSE);
}
return (forwchar(FALSE, 1));
}
/* PRIVATE VERSION OF FORWWORD() FOR WRAPWORD() AND BACKWWORD()
* Move the cursor forward by
* the specified number of words. All of the
* motion is done by "forwchar". Error if you
* try and move beyond the buffer's end.
*/
static
forwwword(f, n)
register int f, n;
{
while (inwword() == FALSE)
{
if (forwchar(FALSE, 1) == FALSE)
return (FALSE);
}
while (inwword() != FALSE)
{
if (forwchar(FALSE, 1) == FALSE)
return (FALSE);
}
return (TRUE);
}
/*
* Move the cursor forward by
* the specified number of words. All of the
* motion is done by "forwchar". Error if you
* try and move beyond the buffer's end.
*/
forwword(f, n)
register int f, n;
{
if (n < 0)
return (backword(f, -n));
while (n--) {
while (inword() == FALSE) {
if (forwchar(FALSE, 1) == FALSE)
return (FALSE);
}
while (inword() != FALSE) {
if (forwchar(FALSE, 1) == FALSE)
return (FALSE);
}
}
return (TRUE);
}
/*
* Move the cursor backward by
* "n" words. All of the details of motion
* are performed by the "backchar" and "forwchar"
* routines. Error if you try to move beyond
* the buffers.
*/
backword(f, n)
register int f, n;
{
if (n < 0)
return (forwword(f, -n));
if (backchar(FALSE, 1) == FALSE)
return (FALSE);
while (n--) {
while (inword() == FALSE) {
if (backchar(FALSE, 1) == FALSE)
return (FALSE);
}
while (inword() != FALSE) {
if (backchar(FALSE, 1) == FALSE)
return (FALSE);
}
}
return (forwchar(FALSE, 1));
}
/*
* Move the cursor forward by
* the specified number of words. As you move,
* convert any characters to upper case. Error
* if you try and move beyond the end of the
* buffer. Bound to "M-U".
*/
upperword(f, n)
register int f, n;
{
register int c;
if (n < 0)
return (FALSE);
while (n--) {
while (inword() == FALSE) {
if (forwchar(FALSE, 1) == FALSE)
return (FALSE);
}
while (inword() != FALSE) {
c = lgetc(curwp->w_dotp, curwp->w_doto);
if (islower(c)) {
c = toupper(c);
lputc(curwp->w_dotp, curwp->w_doto, c);
lchange(WFHARD);
}
if (forwchar(FALSE, 1) == FALSE)
return (FALSE);
}
}
return (TRUE);
}
/*
* Move the cursor forward by
* the specified number of words. As you move
* convert characters to lower ca